<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link href="${ctxStatic}/jquery-easyui/1.4.4/themes/default/easyui.css" rel="stylesheet" type="text/css" />
	<link href="${ctxStatic}/jquery-easyui/1.4.4/themes/icon.css" rel="stylesheet" type="text/css" />
	<link href="${ctxStatic}/jquery-easyui/1.4.4/themes/color.css" rel="stylesheet" type="text/css" />
	<link href="${ctxStatic}/jquery-easyui/1.4.4/demo/demo.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${ctxStatic}/jquery-easyui/1.4.4/jquery.min.js"></script>
	<script type="text/javascript" src="${ctxStatic}/jquery-easyui/1.4.4/jquery.easyui.min.js"></script>
</head>
    <table id="dg" title="模块管理" class="easyui-datagrid" style="width:auto;height:450px"
            url="${ctx }/sys/module/listData"
            toolbar="#toolbar" pagination="true"
            rownumbers="true"  singleSelect="true">
        <thead>
            <tr>
                <th field="moduleCode" width="80" align="center">模块编码</th>
                <th field="moduleName" width="120" align="center">模块名称</th>
                <th field="description" width="400">描述</th>
                <th field="status" width="80" align="center">状态</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
    </div>
    
    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">模块信息</div>
        <form id="fm" method="post" novalidate>
        	 <div class="fitem"  style="display:none;">
                <input name="isNewRecord1" class="easyui-textbox" value="${module.isNewRecord}">
            </div>
            <div class="fitem">
                <label>模块编码:</label>
                <input name="moduleCode" class="easyui-textbox" required="true">
            </div>
            <div class="fitem">
                <label>模块名称:</label>
                <input name="moduleName" class="easyui-textbox" required="true">
            </div>
            <div class="fitem">
                <label>关键类名称:</label>
                <input name="className" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>描述:</label>
                <input name="description" class="easyui-textbox">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
    
       $(document).ready(function(){
    	   
    	  alert($("input[name='isNewRecord']").val()); 
       });
    
        var url;
        function newUser(){
        	//alert("${module.isNewRecord}");
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增模块');
            $('#fm').form('clear');
            url = '${ctx}/sys/module/save';
        }
        function editUser(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','修改模块 ');
                $('#fm').form('load',row);
                url = '${ctx}/sys/module/update?moduleCode='+row.moduleCode;
            }
        }
        function saveUser(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(data){
                	//data = JSON.parse(data);
                	//console.log(data);
                	//console.log(typeof data);
                    var data = eval('('+data+')');
                    if (data.result=="true"){
                    	$.messager.show({
                            title: '提示',
                            msg: data.message
                        });
                    	$('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                        
                    } else {
                    	 $.messager.show({
                             title: '提示',
                             msg: data.message
                         });
                    } 
                }
            });
        }
        function destroyUser(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('确认','确定要删除吗？',function(r){
                    if (r){
                        $.post('${ctx}/sys/module/delete',{moduleCode:row.moduleCode},function(data){
                            if (data.result=="true"){
                            	$.messager.show({    // show error message
                                    title: '提示',
                                    msg: data.message
                                });
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: '错误',
                                    msg: data.message
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
</body>
</html>